import axios, { type AxiosRequestHeaders, type AxiosResponse } from 'axios';
import 'nprogress/nprogress.css'
import NProgress from 'nprogress'
interface ResponseData<T> {
  code: number;
  data: T;  
  message: string;
}

// 配置新建一个 axios 实例
const service = axios.create({
	baseURL: import.meta.env.VITE_API_URL_QT, 
	timeout: 50000,
});

// 添加请求拦截器
service.interceptors.request.use(
	(config) => {
        NProgress.start()
		return config;
	}
);

// 添加响应拦截器
service.interceptors.response.use(
	
	(response: AxiosResponse<ResponseData<any>,any>) => {
		let res =response.data
		NProgress.done()
		return res.data
	},
	(error) => {
		NProgress.done()
		return Promise.reject(error);
	}
);

export default service;
